% sudoku

function[matr] = sudoku(),
flg = 0;

while flg == 0,
    flag = 1;
    matr = ceil(rand([9,9])*9);
    for i = 1:9,
        a = isrepea(matr(:,i));
        if a == 0,
            flg = 0;
            break;
        end;
    end;
    
    if flg == 1,
        for i = 1:9,
        a = isrepea(matr(i,:));
        if a == 0,
            flg = 0;
            break;
        end;
    end;
end;

    if flg == 1,
        for i = 1:3,
            for j = 1:3,
                vect = reshape(matr(i:i+2,j:j+2),[1 9]);
                a = isrepea(vect);
            if a == 0,
            flg = 0;
            break;
        end;
    end;
end;


    
end;
end;


function[flag] = isrepea(vect),
flag = 1;
for i = 1:9,
    for j = i:9,
        if vect(i) == vect(j),
            flag = 0;
        end;
    end;
end;
